package day07;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import work.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TestDemo2 {
    public static void main(String[] args) throws SQLException {
        //c3p0，德鲁伊等都是用装饰设计模式修改了close方法
        ComboPooledDataSource com = new ComboPooledDataSource();
        Connection conn=null;
        PreparedStatement prs;
        ResultSet set=null;
        conn=com.getConnection();
        //使用连接获取sql对象
        //添加test表
//        prs=conn.prepareStatement("CREATE table test (id int primary key , name varchar(20),score int)");
        //添加表数据
//        prs=conn.prepareStatement("INSERT INTO test VALUES (1,'老王',85),(2,'小王',8),(3,'大王',86)");
        //修改表数据
//        prs=conn.prepareStatement("UPDATE  test set score=89 where id=?");
        //删除表数据
//        prs=conn.prepareStatement("DELETE FROM test where id=?");
//        prs.setString(1,"3");
        prs=conn.prepareStatement("SELECT * from test");
        //执行sql对象
//        prs.executeUpdate();
        //对表进行查询
       set = prs.executeQuery();
        while(set.next()){
            int a=set.getInt("id");
            String b=set.getString("name");
            int c=set.getInt("score");
            System.out.println(a+"=="+b+"=="+c);
        }
        //关闭连接
        JDBCUtils.release(conn,prs,set);
    }
}
